# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.exporters import CsvItemExporter


class DoubanscrapyPipeline(object):
    def __init__(self):
        # self.head = ['电影名称', '电影导演', '电影类型', '制片国家/地区', '上映日期', '片长', '豆瓣评分', '豆瓣评论数']
        self.file = open("douban_v2.csv",'ab',encoding='utf-8')
        self.exporter = CsvItemExporter(self.file)
        self.exporter.start_exporting()

    def process_item(self, item, spider):
        self.exporter.export_item(item)
        return item

    def close_spider(self,spider):
        # self.exporter.finish_exporting()
        self.exporter.finish_exporting()
        self.file.close()